package outoforder.leetcode;

import org.junit.Test;

import java.util.Vector;

/**
 * @author shhjiang_001
 * @create 2020-07-01 18:32
 */
public class Solution123 {
    public int maxProfit(int[] prices) {
        int dp_i20 = 0;
        int dp_i21 = Integer.MIN_VALUE;
        int dp_i10 = 0;
        int dp_i11 = Integer.MIN_VALUE;
        for(int price : prices){
            dp_i20 = Math.max(dp_i20,dp_i21+price);
            dp_i21 = Math.max(dp_i10-price,dp_i21);
            dp_i10 = Math.max(dp_i10,dp_i11+price);
            dp_i11 = Math.max(dp_i11,-price);
        }
        return dp_i20;
    }
    @Test
    public void test(){
        System.out.println(maxProfit(new int[]{3, 3, 5, 0, 0, 3, 1, 4}));
    }

}
